basic_url="http://shop.stage.ishangbin.com";//ajax首页
index_url="http://shop.stage.ishangbin.com";//登录界面即主页
getUrl=url2get();
role={"1000":"超级管理员","1001":"管理员","1002":"运营"};//之后要修改
role_type={"1000":{"1001":role["1001"],"1002":role["1002"]},"1001":{"1002":role["1002"]}};
console.warn("角色控制还没有做啊");
error_code={
'200':'成功',
'400':'客户端错误',
'500':'服务端错误',
'201':'用户已经绑定过该类型的sns账号',
'202':'该sns账号已经被别的用户绑定了',
'403':'字典项已经存在',
'402':'字典名称已经存在',
'404':'字典项code已经存在',
'401':'字典助记符已经存在',
'405':'没有查询到',
'4500':'数据非法',
'4544':'缺少必需参数',
'4545':'不支持该请求方式',
'4546':'不支持该类型的content-type',
'4200':'未关注','4201':'重复关注',
'4211':' 会员不存在',
'4212':' 已经是会员身份',
'4220':' 非法卡',
'4221':' 卡已被绑定',
'4222':' 卡已被注销',
'4223':' 卡不存在',
'4224':' 卡未激活',
'4225':' 卡已被停用',
'4226':' 卡已被锁定',
'4230':' 积分已被锁定',
'4240':' 与预留信息不一致',
'4101':' 用户名与密码不匹配',
'4102':' 旧密码不匹配',
'4103':' 账号已被占用',
'4104':' 账号已被修改',
'4105':' 手机号被占用',
'4106':' 手机号不存在',
'4107':' 手机号码不匹配',
'4121':' 验证码不匹配',
'4122':' 验证码已过期',
'4130':' 用户未登录',
'4131':' 用户被锁定',
'4132':' 非法用户',
'4133':' 用户权限不足',
'4140':' 非法Token',
'4141':' Token超时'
};

$(function (){

	$("header").load("/header.html",function(){
		$(".header_user_name").text($.cookie("nickname"));
		$(".header_user_name").text($.cookie("nickname"));
	});// 导航引入
	$(".left_menu").load("/left_menu.html");// 左侧引入
	new loading_css();//导入页面及左侧的CSS内容
	
	//loading_css();//导入页面及左侧的CSS内容
})

function role_check(){//权限信息读取
	role=ajax_send("","/user/type","GET");
	roleArr=new Array();

		for(var x in role.result){
			roleArr[role.result[x].code]=role.result[x].text;
		}
	
	return roleArr;
}

function ajax_send(j,u,h,l){//json,url,http
	url=basic_url +u;
	var redata;
	$.ajax({
		url:url,
		data: j,	
		type: h,
		dataType:"json",
		async:false,
		beforeSend: function(xhr){
			xhr.setRequestHeader( "token", $.cookie("token"));
			if(!l){//
xhr.setRequestHeader( "Content-Type","application/json");
			}
			},//这里设置header
		success: function(data) {
			if(data.code==4140){
				location.href = index_url;
			}
			if(data.code!=200){
			
				alert(error_code[data.code]);
				}
			redata=data;
		
		}
		});

	return redata;
}
function search_result(j,u,h){
//json,url,http,type,type为需要显示的数据模式，如USER,等
	page_data=ajax_send(j,u,h);
	console.log(page_data);
	this.total=page_data.result.total;
	this.items=page_data.result.items;
	json=j;
	json["page"]=1;
	this.page_data=page_data;
	this.guest_show=function (){
		page=this.page_data.result.page;
		$(".result td").parent().remove();
		if(this.total==0){
			append_tem("guest");
			return ;
		}
		for(var i in this.items){
			append=new return_append(this.items[i]);
			append_text=append.guest_append();
			$(".result").append(append_text);
		}
		this.page_add("guest");
		table_id();
		button=new button_click();
		button.guest_click();
	}
	this.user_show=function (){
		page=this.page_data.result.page;
		$(".result td").parent().remove();
		if(this.total==0){
			append_tem("user");
			return ;
		}
		for(var i in this.items){
			append=new return_append(this.items[i]);
			append_text=append.user_append();
			$(".result").append(append_text);
		}
		this.page_add("user");
		button=new button_click();
		button.user_click();
	}
	this.dict_show=function (){
		this.items=this.page_data.result.items;
		page=this.page_data.result.page;
		$(".result td").parent().remove();
		if(this.items.length==0){
			append_tem("dict");
			return ;
		}
		for(var i in this.items){
			append=new return_append(this.items[i]);
			append_text=append.dict_append();
			$(".result").append(append_text);
		}
		this.page_add("dict");
		button=new button_click();
		button.dict_click();
		table_id();
	}
	this.dict_son_show=function (){
		
		this.items=this.page_data.result;;
		$(".result td").parent().remove();
		if(this.items.length==0){
			append_tem("dict_son");
			return ;
		}
		for(var i in this.items){
			append=new return_append(this.items[i]);
			append_text=append.dict_son_append();
			$(".result").append(append_text);
		}
		button=new button_click();
		button.dict_son_click();
		table_id();
	}
	this.page_add=function (t){//添加页码,t为数据内容
			j=this.page_data.result;
			$(".pagesize").text("搜索结果共计"+j.total+"条");
			$(".page").html("");	
			pre="<li class='page_pre'><a class='click'>&laquo;</a></li>";
			next="<li class='page_next'><a class='click'>&raquo;</a></li>";
			pre2="";
			next2="";
			if(j.pageSize<2){
				return;
			}else if(j.pageSize<11){
				start_page=1;
				end_page=j.pageSize+1;
				pre=pre2;
				next=next2;
				num=j.pageSize;
			}else if(j.pageSize>11){
				if(j.page<6){
					start_page=1;
					pre=pre2;
				}else if(j.page>5){
					if(j.pageSize-j.page<11){
						next=next2;
						start_page=j.pageSize-9;
					}else{
						start_page=j.page-5;
					}
				}
				end_page=start_page+10;
			}
			$(".page").append(pre);
			for(var i=start_page;i<end_page;i++){
				$(".page").append("<li class='page_id_"+i+"'><a class='click'>"+i+"</a></li>");
			}
			$(".page"+" .page_id_"+j.page).addClass("active");
			$(".page").append(next);
			delete j;
			$(".page").off().on("click","a",function(){
							c=$(this).parent().attr("class");
							if(c=="page_pre"){
								p=page-1;
							}else if(c=="page_next"){
								p=page+1;
							}else if(c=="disabled"){
								return false;
							}
							else{
								cs=c.split("page_id_");
								p=cs[1];
							}
							json.page=p;
							page_data2=new search_result(json,u,h);
							switch(t){
								case "user":
								page_data2.user_show();
								break;
							    case "dict":
								page_data2.dict_show();
								break;
								case "guest":
								page_data2.guest_show();
								break;
							}
			})
	}
}

function button_click(){//弹出窗口
	$(".result").off();
	this.user_click=function (){
		$(".result").on("click",".resetpassword",function(){//重置密码
			id=$(this).attr("data-id");
			$("#dialog_password_edit input[name=password]").val("");
			data=ajax_send("","/user/"+id,"GET");
			$("#dialog_password_edit .reset_paassword_nickname").text(data.result.nickname);
			$("#dialog_password_edit .reset_paassword_name").text(data.result.name);
			dict_code=new text_clear("user_passord").show();
			$("#dialog_password_edit").off().on("click",".submit",function(){
				obj=$("#dialog_password_edit input[name=password]");
				password=obj.val();
				check=new text_check(password);
				check_result=check.pw_check();
				if(check_result.code==400){
					check.text_error(obj,1);
					return ;
				}
				data=ajax_send("","/user/password/"+id+"?password="+password,"PUT");
				if(data.code!=200){
				alert(error_code[data.code]);
					return;
				}
					alert("修改成功");
					$("#dialog_password_edit").modal("hide");
			});
			$("#dialog_password_edit").modal();
			
		})
		$(".result").on("click",".edit",function(){//修改信息
			id=$(this).attr("data-id");
			data=ajax_send("","/user/"+id,"GET");
			if(data.code==4134){
				alert("您没有权限进行此项操作，请联系管理员");
				return ;
			}
			if(data.code!=200){
				alert(error_code[data.code]);
					return;
			}
			$("#dialog_user_edit input[name=nickname]").val(data.result.nickname);
			$("#dialog_user_edit .edit_user_name").text(data.result.name);

			$("#dialog_user_edit").off().on("click",".submit",function(){
				obj=$("#dialog_user_edit input[name=nickname]");
				type=$("#dialog_user_edit select[name=type]").val();
				
				nickname=obj.val();
				check=new text_check(nickname);
				check_result=check.nk_check();
				if(check_result.code==400){
					check.text_error(obj);
					return ;
				}
				data=ajax_send("","/user/"+id+"?nickname="+nickname+"&type="+type,"PUT");
				if(data.code!=200){
				alert(error_code[data.code]);
					return;
				}
					alert("修改成功");
					data2=ajax_send("","/user/"+id,"GET");
					move_text=new return_append(data2.result);
					edit_move_text=move_text.user_append(1);
					$("#result_id_"+id).html(edit_move_text);
					$("#dialog_user_edit").modal("hide");
			});
			$("#dialog_user_edit").modal();
			
		})
		
		$(".result").on("click",".del",function(){//删除用户
			if(confirm("删除将不可恢复，请慎重！")){
				id=$(this).attr("data-id");
				data=ajax_send("","/user/"+id,"DELETE");
				
				if(data.code==4134){
					alert("您没有权限进行此项操作，请联系管理员");
					return ;
				}
				if(data.code!=200){
				alert(error_code[data.code]);
					return;
				}
				alert("成功删除");
				$("#result_id_"+id).remove();
			}

		})
	}
	this.dict_click=function (){
		$(".result").on("click",".edit",function(){//修改信息
			id=$(this).attr("data-id");
			data=ajax_send("","/dict/"+id,"GET");
			if(data.code==4134){
				alert("您没有权限进行此项操作，请联系管理员");
				return ;
			}
			if(data.code!=200){
				alert(error_code[data.code]);
					return;
				}
			$("#dialog_edit .reset_mnemonic").addClass("form-control-static").html(data.result.mnemonic);
			
			$("#dialog_edit input[name=reset_name]").val(data.result.name);
			$("#dialog_edit input[name=reset_remark]").val(data.result.remark);

			$("#dialog_edit").off().on("click",".submit",function(){
				name=$("#dialog_edit input[name=reset_name]").val();
				remark=$("#dialog_edit input[name=reset_remark]").val();
				json={"name":name,"remark":remark};
				jsons=JSON.stringify(json);
				data=ajax_send(jsons,"/dict/"+id,"PUT");
				if(data.code!=200){
				alert(error_code[data.code]);
					return;
				}
					alert("修改成功");
					data2=ajax_send("","/dict/"+id,"GET");
					move_text=new return_append(data2.result);
					edit_move_text=move_text.dict_append(1);
					$("#result_id_"+id).html(edit_move_text);
					table_id();
					$("#dialog_edit").modal("hide");
				
			});
			$("#dialog_edit").modal();
			
		})
		
		$(".result").on("click",".del",function(){//删除用户
			if(confirm("删除将不可恢复，请慎重！")){
				id=$(this).attr("data-id");
				data=ajax_send("","/dict/"+id,"DELETE");
				if(data.code!=200){
				alert(error_code[data.code]);
					return;
				}
				alert("成功删除");
				$("#result_id_"+id).remove();
			}

		})
	}
	this.dict_son_click=function (){
		$(".result").on("click",".del",function(){//删除用户
			if(confirm("删除将不可恢复，请慎重！")){
				id=$(this).attr("data-id");
				data=ajax_send("","/dict/item/"+id,"DELETE");
				if(data.code!=200){
				alert(error_code[data.code]);
					return;
				}
				alert("成功删除");
				$("#result_id_"+id).remove();
			}

		})
		$(".result").on("click",".edit",function(){
			id=$(this).attr("data-id");
			data=ajax_send("","/dict/item/"+id,"GET");
			$("#dialog_edit *[name=code]").val(data.result.code).attr("disabled","disabled");
			$("#dialog_edit *[name=remark]").val(data.result.remark);
			$("#dialog_edit *[name=text]").val(data.result.text);
			dict_code=new text_clear("dict_code").show();
			dict_text=new text_clear("dict_text").show();
			$("#dialog_edit").off().on("click",".submit",function(){
				obj_text=$("#dialog_edit input[name=text]");
				check_new=new text_check_new();
				text=check_new.dict_text_check(obj_text);
				if(!text){
					return;
				}
				remark=$("#dialog_edit input[name=remark]").val();
				json={"remark":remark,"text":text};
				jsons=JSON.stringify(json);
				data3=ajax_send(jsons,"/dict/item/"+data.result.id,"PUT");
				if(data3.code!=200){
					alert(error_code[data3.code]);
					return;
				}
					alert("修改成功");
					$("#result_id_"+data.result.id+" .result_text").text(text);
					$("#result_id_"+data.result.id+" .result_remark").text(remark);
					$("#dialog_edit").modal("hide");
				
			});
			$("#dialog_edit").modal();
		});
	}
	this.guest_click=function (){
		$(".result ").on('click', '.on,.off', function() {
			if(!$(this).hasClass("active")){//
				post_id=$(this).parents("tr").attr("id");
				post_id=post_id.replace(/[ ]/g,"");
				input_val=$(this).find("input").val();
				json={"state":input_val};
				jsons=JSON.stringify(json);
				post_result=ajax_send(jsons,"/guest/"+post_id+"/state?state="+input_val,"POST");
				if(post_result.code!=200){
					return;
				}
			}
		});
		
	}
	this.remove=function (){
		$(this).remove();
	}
}
function logout(){
	data=ajax_send("","/user/logout","POST");
	if(data.code==200){
		alert("退出成功");
	}
	location.href = index_url;
}

function table_id(){
	$(".result tr").each(function (){
		row=$(this).closest("tr").index();
		if(row>0){
			dd=$(".result tr:eq("+row+")").children(":first").text(row);
		}
	});
}

function check_all(){//全选按钮
		ss=$(".result input");
			text=$(".check_all").text();
				a="全选";
				b="取消";
				if(text==a){
					ss.attr("checked",true);
					$(".check_all").text(b);
				}else if(text=="取消"){
					ss.attr("checked",false);
					$(".check_all").text(a);
					}
			
}

function loading_css(){
	if($.cookie("token")==null ||!$.cookie("token")){
		location.href = index_url;
	}
	$.each($("a"),function(i,link){
		if(!link.href){
		return;
		}
		host_tem=location.host;
		if(link.href.indexOf(host_tem)){
			link_tem=link.href.split(host_tem);
			link.href=index_url+link_tem[1];
			console.log(link.href);
		}else{
			 link.href=index_url+link.href;  
		}
		})	
}

function text_check(str,text){//将被废弃
	this.str=str;
	this.btext="输入正确";//原始提示

	this.user_check=function (){
		text1="长度需在6位以上";//原始提示
		text2="长度需在16位以内";//原始提示
		text3="必须为字母开头,不能含有特殊字符";//原始提示
		if(str.length>16){
		text3=text2;
		}if(str.length<6){
			text3=text1;
		}
		re = /^[a-zA-z]{1}[a-zA-Z0-9]{5,15}$/;
		result=this.check_result(re);
		return result;
	}
	this.pw_check=function (){
		text1="长度需在8位以上";//原始提示
		text2="长度需在20位以内";//原始提示
		text3="不允许出现空格";//原始提示
		if(str.length>20){
			text3=text2;
		}
		if(str.length<8){
			text3=text1;
		}
		/*验证密码
		@长度为8-20
		@不可为中文*/
		re = /^\w{8,20}/;
		result=this.check_result(re);
		return result;
	}
	this.nk_check=function(){
		
		text1="长度需在6位以上";//原始提示
		text2="长度需在20位以内";//原始提示
		text3="不允许出现空格";//原始提示
		/*验证昵称
		@长度为8-20
		@不限制*/
		if(str.length>20){
		text3=text2;
		}
		if(str.length<2){
		text3=text1;
		}
		re =/^[\u4e00-\u9fa5\w\S]{2,20}$/;
		result=this.check_result(re);
		return result;
	}
	this.dict_name_check=function(){
		text1="长度需在2位以上";//原始提示
		text2="长度需在10位以内";//原始提示
		text3="只允许中文";//原始提示
		/*验证昵称
		@长度为8-20
		@不限制*/
		if(str.length>10){
		text3=text2;
		}
		if(str.length<2){
		text3=text1;
		}
		re =/^[\u4e00-\u9fa5]{2,10}$/;
		result=this.check_result(re);
		return result;
	}
	this.dict_mnemonic_check=function(){
		
		text1="长度需在2位以上";//原始提示
		text2="长度需在20位以内";//原始提示
		text3="只允许字母和下划线";//原始提示
		/*验证昵称
		@长度为8-20
		@不限制*/
		if(str.length>20){
		text3=text2;
		}
		if(str.length<2){
		text3=text1;
		}
		re =/^\w{2, 20}$/;
		result=this.check_result(re);
		return result;
	}
	this.dict_code_check=function(){
		text1="1-8位数字";//原始提示
		text2="长度需在1-8位之间";//原始提示
		text3="只允许数字";//原始提示
		/*验证昵称
		@长度为8-20
		@不限制*/
		if(str.length>10||str.length<2){
		text3=text2;
		}
		re =/^[0-9]{2,10}$/;
		result=this.check_result(re);
		return result;
	}
	this.dict_text_check=function(){
		
		text1="1-20位字母数字或汉字";//原始提示
		text2="长度需在1-20位之间";//原始提示
		text3="不允许出现字符";//原始提示
		/*验证昵称
		@长度为8-20
		@不限制*/
		if(str.length>20 || str.length<2){
			text3=text2;
		}
		re =/^[\u4e00-\u9fa5\w]{1,20}$/;
		result=this.check_result(re);
		return result;
	}

	this.check_result=function(re){
		if(re.test(str)){
			result={"code":200,"result":this.btext};
		}else{
			result={"code":400,"result":text3};
		}
		return result;
		
	}
	this.text_error=function (obj,t){
		if(t==1){
			obj=obj.parent();
		}
		obj.parent().addClass("has-error");
		obj.parent().next(".error_text").addClass("text-danger").text(text3);
	}

}


function url2get(){
	try{
		var d=new Array();
		a=window.location.search;
		b=a.split("?");
		c=b[1].split("&");
		for(i=0;i<c.length;i++){
		j=c[i].split("=");
		d[j[0]]=j[1];
		}
		return d;
	}catch(e){
		return false;
	}
	
}

function append_tem(t){

	switch(t){
		case "dict_son":
		r=7;
		break;
		case "dict":
		r=5;
		break;

		case "user":
		r=5;
		break;
		case "guest":
		r=8;
		break;
	}
	$(".result").append("<tr><td class='error' colspan="+r+">抱歉，没有找到您需要的结果</td></tr>");
}


function text_check_new(){//新版检测，传入为json
 	btext="输入正确";
	this.user_name_check=function(obj){//用户名
		str=obj.val();
		if(!str){//
			str="";
		}
		text2="长度需在6-16位之间";//原始提示
		text3="只允许数字";//原始提示
		if(str.length>16||str.length<6){
			text3=text2;
		}
		
		var re = /^[a-zA-z]{1}[a-zA-Z0-9]{5,15}$/;
		result=this.check_result(str,re);
		if(result.code==400){
			this.text_error(obj);
			return false;
		}
		$(".name .has-error").removeClass("has-error");
		return str;
	}
	
	this.user_password_check=function(obj){
		str=obj.val();
		text2="长度需在8-20位之间";//原始提示
		text3="不允许出现空格";//原始提示
		if(str.length>20||str.length<8){
			text3=text2;
		}
		var re = /^\w{8,20}/;
		result=this.check_result(str,re);
		if(result.code==400){
			this.text_error(obj,1);
			return false;
		}
		console.log(result);
		$(".password .has-error").removeClass("has-error");
		return str;
	}
	this.user_password_check2=function(obj,cla){//多密码判断
		str=obj.val();
		text2="长度需在8-20位之间";//原始提示
		text3="不允许出现空格";//原始提示
		if(str.length>20||str.length<8){
			text3=text2;
		}
		var re = /^\w{8,20}/;
		result=this.check_result(str,re);
		if(result.code==400){
			this.text_error(obj,1);
			return false;
		}
		console.log($("."+cla+" .has-error").html());
		$("."+cla+" .has-error").removeClass("has-error");
		$("."+cla+" .text-danger").removeClass("text-danger").text(btext);
		return str;
	}
	this.telphone_check=function(obj){
		str=obj.val();
		console.log(str);
		text3="联系方式格式不匹配";//原始提示
		var re = /^0[1-9]{2,3}-?[2-9][0-9]{6,7}(-?[0-9]{1,4})?|1[0-9]{10}$/;
		result=this.check_result(str,re);
		console.log(result);
		if(result.code==400){
			this.text_error(obj);
			return false;
		}
		$(".telphone .has-error").removeClass("has-error");
		$(".telphone .text-danger").removeClass("text-danger").text(btext);
		return str;
	}
	this.phone_check=function(obj){
		str=obj.val();
		console.log(str);
		text3="固定电话号码格式不匹配";//原始提示
		var re = /^1\d{10}$/;
		result=this.check_result(str,re);
		console.log(result);
		if(result.code==400){
			this.text_error(obj);
			return false;
		}
		$(".telphone .has-error").removeClass("has-error");
		$(".telphone .text-danger").removeClass("text-danger").text(btext);
		return str;
	}
	this.tel_check=function(obj){
		str=obj.val();
		console.log(str);
		text3="固定电话号码格式不匹配";//原始提示
		var re = /^0{3,4}-?[2-9][0-9]{6,7}+(-?[0-9]{1,4})?$/;
		result=this.check_result(str,re);
		console.log(result);
		if(result.code==400){
			this.text_error(obj);
			return false;
		}
		$(".telphone .has-error").removeClass("has-error");
		$(".telphone .text-danger").removeClass("text-danger").text(btext);
		return str;
	}
	this.address_check=function(obj){
		str=obj.val();
		text2="请输入详细地址";
		text3="地址不能超过100位字符";
		if(str<1){
			text3=text2;
			this.text_error(obj);
			return false;
		}else if(str>100){
			this.text_error(obj);
			return false;
		}
		$(".address .has-error").removeClass("has-error");
		$(".address .text-danger").removeClass("text-danger").text(btext);
		return str;
	}
	this.user_nickname_check=function(obj){//昵称
		str=obj.val();

		text2="请输入2-20位的昵称";//原始提示
		text3="不能包含空格和特殊字符";//原始提示
		if(str.length>20||str.length<2){
			text3=text2;
		}

		 var re =/[\u4e00-\u9fa5\w\S]$/;
		result=this.check_result(str,re);
		if(result.code==400){
			this.text_error(obj);
			return false;
		}
		$(".nickname .has-error").removeClass("has-error");
		$(".nickname .text-danger").removeClass("text-danger").text(btext);
		return str;
	}

	this.dict_code_check=function(obj){//字典code检查
		str=obj.val();
		text2="请输入1-8位的纯数字内容";//原始提示
		text3="只允许数字";//原始提示
		/*验证昵称
		@长度为8-20
		@不限制*/
		if(str.length>10||str.length<2){
			text3=text2;
		}

		re =/^[0-9]{2,10}$/;
		result=this.check_result(str,re);
		if(result.code==400){
			this.text_error(obj);
			return false;
		}
		$("#dialog_edit .code .has-error").removeClass("has-error");
		return str;
	}
	this.dict_text_check=function(obj){
		str=obj.val();
		text2="长度需在1-20位之间";//原始提示
		text3="不允许出现字符";//原始提示
		/*验证昵称
		@长度为8-20
		@不限制*/
		if(str.length>20 || str.length<2){
			text3=text2;
		}
		re =/^[\u4e00-\u9fa5\w]{1,20}$/;
		result=this.check_result(str,re);

		if(result.code==400){
			this.text_error(obj);
			return false;
		}
		$("#dialog_edit .text .has-error").removeClass("has-error");
		return str;
	}
	this.dict_name_check=function(obj){
		str=obj.val();
		text2="请输入1-10个中文字符";//原始提示
		text3="只允许中文";//原始提示
		/*验证昵称
		@长度为8-20
		@不限制*/
		if(str.length>10 || str.length<2){
			text3=text2;
		}
		re =/^[\u4e00-\u9fa5]{2,10}$/;
		result=this.check_result(str,re);
		console.log(result);
		if(result.code==400){
			this.text_error(obj);
			return false;
		}
		$("#dialog_edit .name .has-error").removeClass("has-error");
		return str;
	}
	this.dict_mnemonic_check=function(obj){
		str=obj.val();
		text2="长度需在2-20位之间";//原始提示
		text3="只允许字母和下划线";//原始提示
		/*验证昵称
		@长度为8-20
		@不限制*/
		if(str.length>20 || str.length<2){
			text3=text2;
		}
		re =/^[a-zA-Z_]{2,20}$/;
		result=this.check_result(str,re);
		if(result.code==400){
			this.text_error(obj);
			return false;
		}
		$("#dialog_edit .mnemonic .has-error").removeClass("has-error");
		return str;
	}

	this.check_result=function(str,re){
		
		if(re.test(str)){
			result={"code":200};
		}else{
			result={"code":400,"result":text3};
		}
		
		return result;
	}
	this.text_error=function (obj,t){
		if(t==1){
			obj=obj.parent();
		}
		obj.parent().addClass("has-error");
		obj.parent().next(".error_text").addClass("text-danger").text(text3);
	
	}
	this.text_error2=function (obj,t,text4){
		if(t==1){
			obj=obj.parent();
		}
		console.log(text4);
		obj.parent().addClass("has-error");
		obj.parent().next(".error_text").text(text4).addClass("text-danger");
	}

}

function text_clear(t){
		switch(t){
			case "user_passord":
			text={"cla":"passwrod","text":"8-20位"};
			  break;

			case "dict_text":
			text={"cla":"text","text":"1-20位字母数字或汉字"};
			  break;

			case "dict_code":
			text={"cla":"code","text":"1-8位数字"};
			  break;

			case "dict_remark":
 			  break;

			case "dict_mnemonic":
			text={"cla":"mnemonic","text":"2-20位的字母和下划线"};
			  break;

			case "dict_name":
			text={"cla":"name","text":"1-10位中文"};
			break;
			}
		$(".has-error").removeClass("has-error");
		$(".error_text").removeClass("text-danger");
		this.show=function (){
			$("#dialog_edit ."+text.cla+" .error_text").text(text.text);
		}
	}
	
function clear_input(){
	$("input").val("");
}

function open_eye(){
	$(".open_eye").parent().hover(function (){
				$(this).find(".eye").text($(".eye_in").val());
				$(this).find(".eye").height(26);
			},function(){
				$(this).find(".eye").text("");
				$(this).find(".eye").height(0);
			});
}
function add_option(){
	this.industry=function (j){
		item={"url":"/guest/industry","class":"industry","json":j};
		this.result(item);
	};
	this.area_son=function (j,cla,s){
		item={"url":"/dict/area?code="+s,"class":cla,"json":j};
		$("[name="+cla+"]").html("");
		this.result(item);
	};
	this.area=function (j,cla){

		item={"url":"/dict/area","class":cla,"json":j};
		this.result(item);

	};
	this.result=function (item){
		get_result=ajax_send(item.json,item.url,"GET");
		for(var x in get_result.result){

			option="<option value='"+get_result.result[x].code+"'>"+get_result.result[x].text+"</option>";
			$("[name="+item.class+"]").append(option);
		}
		return true;
	}
}


function return_append(e,t){
	this.user_append=function (t){//列出所有user
		type=role[e.type];
		if(e.type==1000){
			type="超级管理员";
		}
		append_text1="<td><input type='checkbox' name='result_id[]' value='"+e.id+"' /></td><td class='result_name'>"+e.name+"</td><td class='result_nickname'>"+e.nickname+"</td><td class='result_type'>"+type+"</td><td class='click_list'>	<A  class='click resetpassword' data-id='"+e.id+"' ><i class='glyphicon glyphicon-repeat'></i>重置密码</A>";
		append_text2="<A class='click del' data-id='"+e.id+"' ><i class='glyphicon glyphicon-remove'></i>删除</A></td>";
		if(t!=1){
			append_text1="<tr id='result_id_"+e.id+"'>"+append_text1;
			append_text2=append_text2+"</tr>";
		}
		

		
		if($.cookie("type")==1000){
			append_text3="<A  class='click edit' data-id='"+e.id+"' ><i class='glyphicon glyphicon-edit'></i>修改</A>";
			append_text=append_text1+append_text3+append_text2;
		}else{
			append_text=append_text1+append_text2;
		}
		return append_text;
	}
	this.dict_append=function (t){//列出所有字典
		append_text="<td></td><td class='result_mnemonic'>"+e.mnemonic+"</td><td class='result_name'>"+e.name+"</td><td class='result_remark'>"+e.remark+"</td><td class='click_list'><A  class='click edit' data-id='"+e.id+"' ><i class='glyphicon glyphicon-edit'></i>修改</A><A  class='click' href='/system/workbook_son.html?id="+e.id+"'><i class='glyphicon glyphicon-repeat'></i>字典项管理</A><A class='click del' data-id='"+e.id+"' ><i class='glyphicon glyphicon-remove'></i>删除</A></td>";
		if(t==1){
			
		}else{
			append_text="<tr id='result_id_"+e.id+"'>"+append_text+"</tr>";
		}
		return append_text;
	}
	this.dict_son_append=function (t){//列出所有字典项
		append_text="<td></td><td class='result_mnemonic'></td><td class='result_name'></td><td class='result_code'>"+e.code+"</td><td class='result_text'>"+e.text+"</td><td class='result_remark'>"+e.remark+"</td><td class='click_list'><a  class='click edit' data-id='"+e.id+"' ><i class='glyphicon glyphicon-edit'></i>修改</a><A class='click del' data-id='"+e.id+"' ><i class='glyphicon glyphicon-remove'></i>删除</A></td>";
		if(t==1){
		}else{
			append_text="<tr id='result_id_"+e.id+"'>"+append_text+"</tr>";
		}
		return append_text;
	}
	this.guest_append=function (t){//列出所有guest
		state={"1001":"开启","1002":"关闭"};
		if(e.state==1001){
			state.on="active";
			state.off="";
		}else{
			state.on="";
			state.off="active";
		}
		state_click='<div class="btn-group col-sm-12" data-toggle="buttons"><label class="btn on '+state.on+' col-sm-6 btn-xs"><input type="radio" class="col-sm-6" name="gender" id="gender1" value="1001" >开启</label><label class="btn off '+state.off+' btn-xs col-sm-6"><input type="radio" class="col-sm-4 " name="gender" id="gender3"  value="1002">关闭</label></div>';
		
		append_text='<tr  id=" '+e.id+'"><td></td><td>'+e.code+'</td><td>'+e.name+'</td><td>'+e.address+'</td><td class="state">'+state_click+'</td><td>2014-08-26</td><td>2014-08-26</td><td><a href="/user/view-1.html?id='+e.id+'"><i class="glyphicon glyphicon-list-alt"></i>查看</a><a href="/user/edit-1.html?id='+e.id+'"><i class="glyphicon glyphicon-edit"></i>修改</a></td></tr>';
		return append_text;
	}
}

 function getObjectURL(file) {
        var url = null ; 
        if (window.createObjectURL!=undefined) { // basic
            url = window.createObjectURL(file) ;
        } else if (window.URL!=undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file) ;
        } else if (window.webkitURL!=undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file) ;
        }
        return url ;
    }
